{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import torch\n",
    "import torch.nn as nn\n",
    "import torch.optim as optim"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'params': [tensor([[ 0.8915,  0.1720,  0.3742],\n",
      "        [ 0.8005,  0.8794,  0.5779],\n",
      "        [ 0.6563,  0.8384,  0.7461]])], 'lr': 0.1, 'momentum': 0, 'dampening': 0, 'weight_decay': 0, 'nesterov': False}]\n"
     ]
    }
   ],
   "source": [
    "w1 = torch.rand(3,3)\n",
    "w1.requires_grad = True\n",
    "optimizer = optim.SGD([w1], lr=0.1)\n",
    "print(optimizer.param_groups)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'params': [tensor([[ 0.8915,  0.1720,  0.3742],\n",
      "        [ 0.8005,  0.8794,  0.5779],\n",
      "        [ 0.6563,  0.8384,  0.7461]])], 'lr': 0.1, 'momentum': 0, 'dampening': 0, 'weight_decay': 0, 'nesterov': False}, {'params': [tensor([[ 0.4433,  0.5675,  0.0681],\n",
      "        [ 0.9803,  0.9481,  0.7094],\n",
      "        [ 0.1209,  0.6489,  0.6493]])], 'lr': 0.1, 'momentum': 0, 'dampening': 0, 'weight_decay': 0, 'nesterov': False}]\n"
     ]
    }
   ],
   "source": [
    "w2 = torch.rand(3,3)\n",
    "w2.requires_grad=True\n",
    "optimizer.add_param_group({'params': w2})\n",
    "print(optimizer.param_groups)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'params': [tensor([[ 0.4433,  0.5675,  0.0681],\n",
      "        [ 0.9803,  0.9481,  0.7094],\n",
      "        [ 0.1209,  0.6489,  0.6493]])], 'lr': 0.1, 'momentum': 0.9, 'dampening': 0, 'weight_decay': 0, 'nesterov': False}\n"
     ]
    }
   ],
   "source": [
    "optimizer.param_groups[1]['momentum'] = 0.9\n",
    "print(optimizer.param_groups[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "lamb1 = lambda epoch: 0.9 ** epoch\n",
    "lamb2 = lambda epoch: 0.8 ** epoch\n",
    "schedular = optim.lr_scheduler.LambdaLR(optimizer,lr_lambda=[lamb1,lamb2], last_epoch =-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "schedular = optim.lr_scheduler.StepLR(optimizer,step_size=3, gamma=0.9, last_epoch =-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
